package com.itbour.service.material.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.material.MediaInfoDao;
import com.itbour.dto.com.MediaInfoDto;
import com.itbour.service.material.MediaInfoService;

public class MediaInfoServiceImpl implements MediaInfoService {
	
	private MediaInfoDao  mediaInfoDao;
	
	
	// 分页获取音频和视频信息
	public Page pageGetMediaInfo(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = mediaInfoDao.getMediaInfoCnt(parm);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			parm.put("pageSize", pageSize);
			parm.put("skipResults", skipResults);
			List<MediaInfoDto> data = mediaInfoDao.getMediaInfo(parm);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}


	// 生成Set和Get方法
	public MediaInfoDao getMediaInfoDao() {
		return mediaInfoDao;
	}
	public void setMediaInfoDao(MediaInfoDao mediaInfoDao) {
		this.mediaInfoDao = mediaInfoDao;
	}


	// 新建媒体
	public void addMedia(MediaInfoDto media) {
		Map<String, Object> parm = new HashMap<String, Object>();
		parm.put("media_type", media.getMedia_type());
		parm.put("use", media.getUse());
		parm.put("user_type", media.getUser_type());
		parm.put("user_id", media.getUser_id());
		parm.put("media_name", media.getMedia_name());
		parm.put("thumbs", "");
		parm.put("duration", media.getDuration());
		parm.put("url", media.getUrl());
		parm.put("update_by", "Add:"+media.getUser_id());//
		mediaInfoDao.addMediaInfo(parm);
	}
}
